import random
import requests as req
import math
import json

def generate_running_path(input_list):
    running_path = []
    for i, point in enumerate(input_list):
        running_path.append(point)
        if i < len(input_list) - 1:
            current_point = (point['latitude'], point['longitude'])
            next_point = (input_list[i + 1]['latitude'], input_list[i + 1]['longitude'])
            distance = calculate_distance(current_point, next_point)
            num_steps = int(distance)
            print(num_steps)
            for j in range(num_steps):
                print("asdf")
                offset_lat, offset_lon = generate_random_offset()
                new_latitude = current_point[0] + offset_lat
                new_longitude = current_point[1] + offset_lon
                running_path.append({'t': point['t'], 'latitude': new_latitude, 'longitude': new_longitude})
    return running_path

def calculate_distance(point1, point2):
    # 使用球面三角法计算两点之间的距离
    lat1, lon1 = point1
    lat2, lon2 = point2
    radius = 6371  # 地球平均半径（单位：km）
    dlat = math.radians(lat2 - lat1)
    dlon = math.radians(lon2 - lon1)
    a = math.sin(dlat / 2) * math.sin(dlat / 2) + math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) * math.sin(dlon / 2) * math.sin(dlon / 2)
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    distance = radius * c
    return distance

def generate_random_offset():
    # 生成微小的经纬度偏移量
    # 这里使用简单的随机漫步模型，可以根据需要进行调整
    offset_range = 0.0001  # 经纬度的偏移范围，可根据实际情况进行调整
    offset_lat = random.uniform(-offset_range, offset_range)
    offset_lon = random.uniform(-offset_range, offset_range)
    print(offset_lat,offset_lon)
    return offset_lat, offset_lon

# 示例数据
jsonstr = req.get(url="http://temp.x.1314.cool/index.php").text
data = json.loads(jsonstr)
input_list = [
    {"t": 1686106278834, "latitude": 36.124069, "longitude": 120.484304},
    {"t": 1686106280832, "latitude": 36.124116, "longitude": 120.484291},
    # ...
]

running_path = generate_running_path(data)

#print(running_path)
